home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12052 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: news1.erols.com!newsmaster@erols.com
  2. From: Chris Cobb <ccobb@cseg.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Floating Point Error Traping by try and catch:-
  5. Date: 18 Mar 1996 01:29:18 GMT
  6. Organization: CSEG, Inc.
  7. Message-ID: <4iie9e$1pp@news5.erols.com>
  8. References: <4i836n$2u8@dfw-ixnews5.ix.netcom.com>
  9. NNTP-Posting-Host: ccobb.erols.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22KIT (Windows; U; 16bit)
  14.  
  15. rajash@ix.netcom.com(Rajash Gopalakrishnan ) wrote:
  16. >Hi Experts!.
  17. >
  18. >We were using normal try and catch statements to trap
  19. >the exceptional errors occured during C++ class operation.
  20. >We are working on Soaris C++ 4.1 with Toolsh++ classes.
  21. >
  22. [stuff deleted]
  23. >Here what I found is that before catch, arithemetic experssion fault 
  24. >occurs and core is dumping. One method I found is to redirect the
  25. >signal
  26. >handler and do a catch but that's a round about method. Can anybody 
  27. >explain how we can handle this situation by try and catch alone. Is
  28. >there
  29. >any method to show where error occured and line#.
  30.  
  31. Well, it seems to me that a floating point error is a hardware trap
  32. which you may be able to intercept with a signal function (I haven't
  33. tried to catch one lately).  Within your signal function you could
  34. then perform a throw.
  35.  
  36. Then only way I can see how you could do this without a signal function
  37. is to override operator/, but you would have to create your own class
  38. that could be overriden, such as 'class Long'.
  39.  
  40. Getting the line number would be tough...once you're in operator /, you
  41. would not know the line number of your caller.
  42.  
  43. If you *really* wanted the line number and didn't mind getting hackish 
  44. and obscure, you could define an inline function div(long,long) which
  45. would divide two longs.  However, you also define a second inline
  46. div(long,long,char*file,int line).  Then (and here's the hackish part)
  47. you define a macro:
  48.  
  49. #if defined(TRACK_LINE_NUMBERS)
  50. #define div(l1,l2) div(l1,l2,__FILE__,__LINE__)
  51. #endif
  52.  
  53. Then whenever you called div() the current file and line number would be 
  54. passed to it and if a zero denominator was passed, an object containing 
  55. the file and line could be thrown.  Viola!
  56.  
  57. Chris
  58.  
  59.  
  60.  
  61.  
  62.